﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using WinnerCMS.BLL;
namespace WinnerCMS.PlugIn.FileWatcher
{
    public static class Action
    {

        /// <summary>
        /// 最大扫描文件体积
        /// </summary>
        static private long _MaxSize = 2097152;//默认2M
        /// <summary>
        /// 最小扫描文件体积
        /// </summary>
        static private long _MinSize = 10;//默认10字节


        #region 忽略文件
        /// <summary>
        /// 忽略文件
        /// </summary>
        /// <param name="FileSize"></param>
        /// <returns></returns>
        static public bool Ignore(long FileSize)
        {
            if (FileSize < _MinSize)
            {
                return true;
            }
            if (FileSize > _MaxSize)
            {
                return true;
            }
            return false;
        }
        /// <summary>
        /// 忽略文件
        /// </summary>
        /// <param name="fi"></param>
        /// <returns></returns>
        static public bool Ignore(FileInfo fi)
        {
            string strFullName = fi.FullName;
            if (strFullName.IndexOf(@"\bin\") != -1)
            {
                return true;
            }
            else
            {
                if (strFullName.IndexOf(@"/bin/", System.StringComparison.Ordinal) != -1)
                {
                    return true;
                }
            }

            switch (fi.Extension.ToLower())
            {
                case ".dll":
                case ".cs":
                case ".html":
                case ".js":
                    return true;
                default:
                    CMSConfig config = CMSConfig.Instance();
                    var arr = config.FileWatcher.IgnorePostfix;

                    return arr.Any(str => str.Equals(fi.Extension, StringComparison.CurrentCultureIgnoreCase));
            }
        }
        #endregion
    }


}